package yu.code.yurpc.proxy;


import yu.code.yurpc.RpcApplication;

import java.lang.reflect.Proxy;

/**
 * 服务代理工程（用于生成服务代理对象）
 */
public class ServiceProxyFactory {
    public static<T> T getProxy(Class<T> serviceClass){
        //判断是否启用Mock
        if(RpcApplication.getRpcConfig().isMock()){
            return getMockProxy(serviceClass);
        }
        return (T) Proxy.newProxyInstance(
                serviceClass.getClassLoader(),
                new Class<?>[]{serviceClass},
                new ServiceProxy());
    }
    public static<T> T getMockProxy(Class<T> serviceClass){
        return (T) Proxy.newProxyInstance(
                serviceClass.getClassLoader(),
                new Class<?>[]{serviceClass},
                new MockServiceProxy());
    }
}
